﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using HslCommunication.BasicFramework;
using HslCommunication.Core;
using HslCommunication.Core.Address;
using HslCommunication.Core.IMessage;
using HslCommunication.Core.Net;
using HslCommunication.LogNet;
using HslCommunication.Reflection;

namespace HslCommunication.Profinet.Siemens
{
	/// <summary>
	/// <b>[商业授权]</b> 西门子S7协议的虚拟服务器，支持TCP协议，模拟的是1200的PLC进行通信，在客户端进行操作操作的时候，最好是选择1200的客户端对象进行通信。<br />
	/// <b>[Authorization]</b> The virtual server of Siemens S7 protocol supports TCP protocol. It simulates 1200 PLC for communication. When the client is operating, it is best to select the 1200 client object for communication.
	/// </summary>
	/// <remarks>
	/// 本西门子的虚拟PLC仅限商业授权用户使用，感谢支持。
	/// <note type="important">对于200smartPLC的V区，就是DB1.X，例如，V100=DB1.100</note>
	/// </remarks>
	/// <example>
	/// 地址支持的列表如下：
	/// <list type="table">
	///   <listheader>
	///     <term>地址名称</term>
	///     <term>地址代号</term>
	///     <term>示例</term>
	///     <term>地址进制</term>
	///     <term>字操作</term>
	///     <term>位操作</term>
	///     <term>备注</term>
	///   </listheader>
	///   <item>
	///     <term>中间寄存器</term>
	///     <term>M</term>
	///     <term>M100,M200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>输入寄存器</term>
	///     <term>I</term>
	///     <term>I100,I200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>输出寄存器</term>
	///     <term>Q</term>
	///     <term>Q100,Q200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>DB块寄存器</term>
	///     <term>DB</term>
	///     <term>DB1.100,DB1.200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>V寄存器</term>
	///     <term>V</term>
	///     <term>V100,V200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term>V寄存器本质就是DB块1</term>
	///   </item>
	///   <item>
	///     <term>定时器的值</term>
	///     <term>T</term>
	///     <term>T100,T200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term>未测试通过</term>
	///   </item>
	///   <item>
	///     <term>计数器的值</term>
	///     <term>C</term>
	///     <term>C100,C200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term>未测试通过</term>
	///   </item>
	/// </list>
	/// 你可以很快速并且简单的创建一个虚拟的s7服务器
	/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\SiemensS7ServerExample.cs" region="UseExample1" title="简单的创建服务器" />
	/// 当然如果需要高级的服务器，指定日志，限制客户端的IP地址，获取客户端发送的信息，在服务器初始化的时候就要参照下面的代码：
	/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\SiemensS7ServerExample.cs" region="UseExample4" title="定制服务器" />
	/// 服务器创建好之后，我们就可以对服务器进行一些读写的操作了，下面的代码是基础的BCL类型的读写操作。
	/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\SiemensS7ServerExample.cs" region="ReadWriteExample" title="基础的读写示例" />
	/// 高级的对于byte数组类型的数据进行批量化的读写操作如下：   
	/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\SiemensS7ServerExample.cs" region="BytesReadWrite" title="字节的读写示例" />
	/// 更高级操作请参见源代码。
	/// </example>
	// Token: 0x02000050 RID: 80
	public class SiemensS7Server : NetworkDataServerBase
	{
		/// <summary>
		/// 实例化一个S7协议的服务器，支持I，Q，M，DB1.X, DB2.X, DB3.X 数据区块的读写操作<br />
		/// Instantiate a server with S7 protocol, support I, Q, M, DB1.X data block read and write operations
		/// </summary>
		// Token: 0x060006A6 RID: 1702 RVA: 0x00021674 File Offset: 0x0001F874
		public SiemensS7Server()
		{
			this.inputBuffer = new SoftBuffer(65536);
			this.outputBuffer = new SoftBuffer(65536);
			this.memeryBuffer = new SoftBuffer(65536);
			this.db1BlockBuffer = new SoftBuffer(65536);
			this.db2BlockBuffer = new SoftBuffer(65536);
			this.db3BlockBuffer = new SoftBuffer(65536);
			this.dbOtherBlockBuffer = new SoftBuffer(65536);
			this.countBuffer = new SoftBuffer(131072);
			this.timerBuffer = new SoftBuffer(131072);
			base.WordLength = 2;
			base.ByteTransform = new ReverseBytesTransform();
		}

		// Token: 0x060006A7 RID: 1703 RVA: 0x00021730 File Offset: 0x0001F930
		private OperateResult<SoftBuffer> GetDataAreaFromS7Address(S7AddressData s7Address)
		{
			byte dataCode = s7Address.DataCode;
			byte b = dataCode;
			OperateResult<SoftBuffer> result;
			if (b != 30)
			{
				if (b != 31)
				{
					switch (b)
					{
					case 129:
						result = OperateResult.CreateSuccessResult<SoftBuffer>(this.inputBuffer);
						break;
					case 130:
						result = OperateResult.CreateSuccessResult<SoftBuffer>(this.outputBuffer);
						break;
					case 131:
						result = OperateResult.CreateSuccessResult<SoftBuffer>(this.memeryBuffer);
						break;
					case 132:
					{
						bool flag = s7Address.DbBlock == 1;
						if (flag)
						{
							result = OperateResult.CreateSuccessResult<SoftBuffer>(this.db1BlockBuffer);
						}
						else
						{
							bool flag2 = s7Address.DbBlock == 2;
							if (flag2)
							{
								result = OperateResult.CreateSuccessResult<SoftBuffer>(this.db2BlockBuffer);
							}
							else
							{
								bool flag3 = s7Address.DbBlock == 3;
								if (flag3)
								{
									result = OperateResult.CreateSuccessResult<SoftBuffer>(this.db3BlockBuffer);
								}
								else
								{
									result = OperateResult.CreateSuccessResult<SoftBuffer>(this.dbOtherBlockBuffer);
								}
							}
						}
						break;
					}
					default:
						result = new OperateResult<SoftBuffer>(StringResources.Language.NotSupportedDataType);
						break;
					}
				}
				else
				{
					result = OperateResult.CreateSuccessResult<SoftBuffer>(this.timerBuffer);
				}
			}
			else
			{
				result = OperateResult.CreateSuccessResult<SoftBuffer>(this.countBuffer);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.Read(System.String,System.UInt16)" />
		// Token: 0x060006A8 RID: 1704 RVA: 0x00021844 File Offset: 0x0001FA44
		[HslMqttApi("ReadByteArray", "")]
		public override OperateResult<byte[]> Read(string address, ushort length)
		{
			OperateResult<S7AddressData> operateResult = S7AddressData.ParseFrom(address, length);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				OperateResult<SoftBuffer> dataAreaFromS7Address = this.GetDataAreaFromS7Address(operateResult.Content);
				bool flag2 = !dataAreaFromS7Address.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<byte[]>(dataAreaFromS7Address);
				}
				else
				{
					bool flag3 = operateResult.Content.DataCode == 30 || operateResult.Content.DataCode == 31;
					if (flag3)
					{
						result = OperateResult.CreateSuccessResult<byte[]>(dataAreaFromS7Address.Content.GetBytes(operateResult.Content.AddressStart * 2, (int)(length * 2)));
					}
					else
					{
						result = OperateResult.CreateSuccessResult<byte[]>(dataAreaFromS7Address.Content.GetBytes(operateResult.Content.AddressStart / 8, (int)length));
					}
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.Write(System.String,System.Byte[])" />
		// Token: 0x060006A9 RID: 1705 RVA: 0x00021904 File Offset: 0x0001FB04
		[HslMqttApi("WriteByteArray", "")]
		public override OperateResult Write(string address, byte[] value)
		{
			OperateResult<S7AddressData> operateResult = S7AddressData.ParseFrom(address);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				OperateResult<SoftBuffer> dataAreaFromS7Address = this.GetDataAreaFromS7Address(operateResult.Content);
				bool flag2 = !dataAreaFromS7Address.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<byte[]>(dataAreaFromS7Address);
				}
				else
				{
					bool flag3 = operateResult.Content.DataCode == 30 || operateResult.Content.DataCode == 31;
					if (flag3)
					{
						dataAreaFromS7Address.Content.SetBytes(value, operateResult.Content.AddressStart * 2);
					}
					else
					{
						dataAreaFromS7Address.Content.SetBytes(value, operateResult.Content.AddressStart / 8);
					}
					result = OperateResult.CreateSuccessResult();
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.ReadByte(System.String)" />
		// Token: 0x060006AA RID: 1706 RVA: 0x0001C2EB File Offset: 0x0001A4EB
		[HslMqttApi("ReadByte", "")]
		public OperateResult<byte> ReadByte(string address)
		{
			return ByteTransformHelper.GetResultFromArray<byte>(this.Read(address, 1));
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.Write(System.String,System.Byte)" />
		// Token: 0x060006AB RID: 1707 RVA: 0x0001C2FA File Offset: 0x0001A4FA
		[HslMqttApi("WriteByte", "")]
		public OperateResult Write(string address, byte value)
		{
			return this.Write(address, new byte[]
			{
				value
			});
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.ReadBool(System.String)" />
		// Token: 0x060006AC RID: 1708 RVA: 0x000219C0 File Offset: 0x0001FBC0
		[HslMqttApi("ReadBool", "")]
		public override OperateResult<bool> ReadBool(string address)
		{
			OperateResult<S7AddressData> operateResult = S7AddressData.ParseFrom(address);
			bool flag = !operateResult.IsSuccess;
			OperateResult<bool> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool>(operateResult);
			}
			else
			{
				OperateResult<SoftBuffer> dataAreaFromS7Address = this.GetDataAreaFromS7Address(operateResult.Content);
				bool flag2 = !dataAreaFromS7Address.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<bool>(dataAreaFromS7Address);
				}
				else
				{
					result = OperateResult.CreateSuccessResult<bool>(dataAreaFromS7Address.Content.GetBool(operateResult.Content.AddressStart));
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Siemens.SiemensS7Net.Write(System.String,System.Boolean)" />
		// Token: 0x060006AD RID: 1709 RVA: 0x00021A30 File Offset: 0x0001FC30
		[HslMqttApi("WriteBool", "")]
		public override OperateResult Write(string address, bool value)
		{
			OperateResult<S7AddressData> operateResult = S7AddressData.ParseFrom(address);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult<SoftBuffer> dataAreaFromS7Address = this.GetDataAreaFromS7Address(operateResult.Content);
				bool flag2 = !dataAreaFromS7Address.IsSuccess;
				if (flag2)
				{
					result = dataAreaFromS7Address;
				}
				else
				{
					dataAreaFromS7Address.Content.SetBool(value, operateResult.Content.AddressStart);
					result = OperateResult.CreateSuccessResult();
				}
			}
			return result;
		}

		/// <inheritdoc />
		// Token: 0x060006AE RID: 1710 RVA: 0x00021A98 File Offset: 0x0001FC98
		protected override void ThreadPoolLoginAfterClientCheck(Socket socket, IPEndPoint endPoint)
		{
			S7Message netMessage = new S7Message();
			OperateResult<byte[]> operateResult = base.ReceiveByMessage(socket, 5000, netMessage, null);
			bool flag = !operateResult.IsSuccess;
			if (!flag)
			{
				OperateResult operateResult2 = base.Send(socket, SoftBasic.HexStringToBytes("03 00 00 16 02 D0 80 32 01 00 00 02 00 00 08 00 00 f0 00 00 01 00"));
				bool flag2 = !operateResult2.IsSuccess;
				if (!flag2)
				{
					OperateResult<byte[]> operateResult3 = base.ReceiveByMessage(socket, 5000, netMessage, null);
					bool flag3 = !operateResult3.IsSuccess;
					if (!flag3)
					{
						OperateResult operateResult4 = base.Send(socket, SoftBasic.HexStringToBytes("03 00 00 1B 02 f0 80 32 01 00 00 02 00 00 08 00 00 00 00 00 01 00 01 00 f0 00 f0"));
						bool flag4 = !operateResult4.IsSuccess;
						if (!flag4)
						{
							AppSession appSession = new AppSession();
							appSession.IpEndPoint = endPoint;
							appSession.WorkSocket = socket;
							try
							{
								socket.BeginReceive(new byte[0], 0, 0, SocketFlags.None, new AsyncCallback(this.SocketAsyncCallBack), appSession);
								base.AddClient(appSession);
							}
							catch
							{
								socket.Close();
								ILogNet logNet = base.LogNet;
								if (logNet != null)
								{
									logNet.WriteDebug(this.ToString(), string.Format(StringResources.Language.ClientOfflineInfo, endPoint));
								}
							}
						}
					}
				}
			}
		}

		// Token: 0x060006AF RID: 1711 RVA: 0x00021BC8 File Offset: 0x0001FDC8
		[DebuggerStepThrough]
		private void SocketAsyncCallBack(IAsyncResult ar)
		{
			SiemensS7Server.<SocketAsyncCallBack>d__9 <SocketAsyncCallBack>d__ = new SiemensS7Server.<SocketAsyncCallBack>d__9();
			<SocketAsyncCallBack>d__.<>t__builder = AsyncVoidMethodBuilder.Create();
			<SocketAsyncCallBack>d__.<>4__this = this;
			<SocketAsyncCallBack>d__.ar = ar;
			<SocketAsyncCallBack>d__.<>1__state = -1;
			<SocketAsyncCallBack>d__.<>t__builder.Start<SiemensS7Server.<SocketAsyncCallBack>d__9>(ref <SocketAsyncCallBack>d__);
		}

		// Token: 0x060006B0 RID: 1712 RVA: 0x00021C08 File Offset: 0x0001FE08
		private byte[] ReadByMessage(byte[] packCommand)
		{
			List<byte> list = new List<byte>();
			int num = (int)packCommand[18];
			int num2 = 19;
			for (int i = 0; i < num; i++)
			{
				byte b = packCommand[num2 + 1];
				byte[] command = packCommand.SelectMiddle(num2, (int)(b + 2));
				num2 += (int)(b + 2);
				list.AddRange(this.ReadByCommand(command));
			}
			byte[] array = new byte[21 + list.Count];
			SoftBasic.HexStringToBytes("03 00 00 1A 02 F0 80 32 03 00 00 00 01 00 02 00 05 00 00 04 01").CopyTo(array, 0);
			array[2] = (byte)(array.Length / 256);
			array[3] = (byte)(array.Length % 256);
			array[15] = (byte)(list.Count / 256);
			array[16] = (byte)(list.Count % 256);
			array[20] = packCommand[18];
			list.CopyTo(array, 21);
			return array;
		}

		// Token: 0x060006B1 RID: 1713 RVA: 0x00021CDC File Offset: 0x0001FEDC
		private byte[] ReadByCommand(byte[] command)
		{
			bool flag = command[3] == 1;
			byte[] result;
			if (flag)
			{
				int num = (int)command[9] * 65536 + (int)command[10] * 256 + (int)command[11];
				ushort dbBlock = base.ByteTransform.TransUInt16(command, 6);
				OperateResult<SoftBuffer> dataAreaFromS7Address = this.GetDataAreaFromS7Address(new S7AddressData
				{
					AddressStart = num,
					DataCode = command[8],
					DbBlock = dbBlock,
					Length = 1
				});
				bool flag2 = !dataAreaFromS7Address.IsSuccess;
				if (flag2)
				{
					throw new Exception(dataAreaFromS7Address.Message);
				}
				result = this.PackReadBitCommandBack(dataAreaFromS7Address.Content.GetBool(num));
			}
			else
			{
				bool flag3 = command[3] == 30 || command[3] == 31;
				if (flag3)
				{
					ushort num2 = base.ByteTransform.TransUInt16(command, 4);
					int num3 = (int)command[9] * 65536 + (int)command[10] * 256 + (int)command[11];
					OperateResult<SoftBuffer> dataAreaFromS7Address2 = this.GetDataAreaFromS7Address(new S7AddressData
					{
						AddressStart = num3,
						DataCode = command[8],
						DbBlock = 0,
						Length = num2
					});
					bool flag4 = !dataAreaFromS7Address2.IsSuccess;
					if (flag4)
					{
						throw new Exception(dataAreaFromS7Address2.Message);
					}
					result = this.PackReadCTCommandBack(dataAreaFromS7Address2.Content.GetBytes(num3 * 2, (int)(num2 * 2)), (command[3] == 30) ? 3 : 5);
				}
				else
				{
					ushort length = base.ByteTransform.TransUInt16(command, 4);
					ushort dbBlock2 = base.ByteTransform.TransUInt16(command, 6);
					int num4 = ((int)command[9] * 65536 + (int)command[10] * 256 + (int)command[11]) / 8;
					OperateResult<SoftBuffer> dataAreaFromS7Address3 = this.GetDataAreaFromS7Address(new S7AddressData
					{
						AddressStart = num4,
						DataCode = command[8],
						DbBlock = dbBlock2,
						Length = length
					});
					bool flag5 = !dataAreaFromS7Address3.IsSuccess;
					if (flag5)
					{
						throw new Exception(dataAreaFromS7Address3.Message);
					}
					result = this.PackReadWordCommandBack(dataAreaFromS7Address3.Content.GetBytes(num4, (int)length));
				}
			}
			return result;
		}

		// Token: 0x060006B2 RID: 1714 RVA: 0x00021EEC File Offset: 0x000200EC
		private byte[] PackReadWordCommandBack(byte[] result)
		{
			byte[] array = new byte[4 + result.Length];
			array[0] = byte.MaxValue;
			array[1] = 4;
			base.ByteTransform.TransByte((ushort)result.Length).CopyTo(array, 2);
			result.CopyTo(array, 4);
			return array;
		}

		// Token: 0x060006B3 RID: 1715 RVA: 0x00021F38 File Offset: 0x00020138
		private byte[] PackReadCTCommandBack(byte[] result, int dataLength)
		{
			byte[] array = new byte[4 + result.Length * dataLength / 2];
			array[0] = byte.MaxValue;
			array[1] = 9;
			base.ByteTransform.TransByte((ushort)(array.Length - 4)).CopyTo(array, 2);
			for (int i = 0; i < result.Length / 2; i++)
			{
				result.SelectMiddle(i * 2, 2).CopyTo(array, 4 + dataLength - 2 + i * dataLength);
			}
			return array;
		}

		// Token: 0x060006B4 RID: 1716 RVA: 0x00021FB0 File Offset: 0x000201B0
		private byte[] PackReadBitCommandBack(bool value)
		{
			return new byte[]
			{
				byte.MaxValue,
				3,
				0,
				1,
				value ? 1 : 0
			};
		}

		// Token: 0x060006B5 RID: 1717 RVA: 0x00021FEC File Offset: 0x000201EC
		private byte[] WriteByMessage(byte[] packCommand)
		{
			bool flag = packCommand[22] == 2;
			byte[] result;
			if (flag)
			{
				ushort dbBlock = base.ByteTransform.TransUInt16(packCommand, 25);
				int length = (int)base.ByteTransform.TransInt16(packCommand, 23);
				int destIndex = ((int)packCommand[28] * 65536 + (int)packCommand[29] * 256 + (int)packCommand[30]) / 8;
				byte[] data = base.ByteTransform.TransByte(packCommand, 35, length);
				OperateResult<SoftBuffer> dataAreaFromS7Address = this.GetDataAreaFromS7Address(new S7AddressData
				{
					DataCode = packCommand[27],
					DbBlock = dbBlock,
					Length = 1
				});
				bool flag2 = !dataAreaFromS7Address.IsSuccess;
				if (flag2)
				{
					throw new Exception(dataAreaFromS7Address.Message);
				}
				dataAreaFromS7Address.Content.SetBytes(data, destIndex);
				result = SoftBasic.HexStringToBytes("03 00 00 16 02 F0 80 32 03 00 00 00 01 00 02 00 01 00 00 05 01 FF");
			}
			else
			{
				ushort dbBlock2 = base.ByteTransform.TransUInt16(packCommand, 25);
				int destIndex2 = (int)packCommand[28] * 65536 + (int)packCommand[29] * 256 + (int)packCommand[30];
				bool value = packCommand[35] > 0;
				OperateResult<SoftBuffer> dataAreaFromS7Address2 = this.GetDataAreaFromS7Address(new S7AddressData
				{
					DataCode = packCommand[27],
					DbBlock = dbBlock2,
					Length = 1
				});
				bool flag3 = !dataAreaFromS7Address2.IsSuccess;
				if (flag3)
				{
					throw new Exception(dataAreaFromS7Address2.Message);
				}
				dataAreaFromS7Address2.Content.SetBool(value, destIndex2);
				result = SoftBasic.HexStringToBytes("03 00 00 16 02 F0 80 32 03 00 00 00 01 00 02 00 01 00 00 05 01 FF");
			}
			return result;
		}

		/// <inheritdoc />
		// Token: 0x060006B6 RID: 1718 RVA: 0x00022158 File Offset: 0x00020358
		protected override void LoadFromBytes(byte[] content)
		{
			bool flag = content.Length < 458752;
			if (flag)
			{
				throw new Exception("File is not correct");
			}
			this.inputBuffer.SetBytes(content, 0, 0, 65536);
			this.outputBuffer.SetBytes(content, 65536, 0, 65536);
			this.memeryBuffer.SetBytes(content, 131072, 0, 65536);
			this.db1BlockBuffer.SetBytes(content, 196608, 0, 65536);
			this.db2BlockBuffer.SetBytes(content, 262144, 0, 65536);
			this.db3BlockBuffer.SetBytes(content, 327680, 0, 65536);
			this.dbOtherBlockBuffer.SetBytes(content, 393216, 0, 65536);
			bool flag2 = content.Length < 720896;
			if (!flag2)
			{
				this.countBuffer.SetBytes(content, 458752, 0, 131072);
				this.timerBuffer.SetBytes(content, 589824, 0, 131072);
			}
		}

		/// <inheritdoc />
		// Token: 0x060006B7 RID: 1719 RVA: 0x00022264 File Offset: 0x00020464
		protected override byte[] SaveToBytes()
		{
			byte[] array = new byte[720896];
			Array.Copy(this.inputBuffer.GetBytes(), 0, array, 0, 65536);
			Array.Copy(this.outputBuffer.GetBytes(), 0, array, 65536, 65536);
			Array.Copy(this.memeryBuffer.GetBytes(), 0, array, 131072, 65536);
			Array.Copy(this.db1BlockBuffer.GetBytes(), 0, array, 196608, 65536);
			Array.Copy(this.db2BlockBuffer.GetBytes(), 0, array, 262144, 65536);
			Array.Copy(this.db3BlockBuffer.GetBytes(), 0, array, 327680, 65536);
			Array.Copy(this.dbOtherBlockBuffer.GetBytes(), 0, array, 393216, 65536);
			Array.Copy(this.countBuffer.GetBytes(), 0, array, 458752, 131072);
			Array.Copy(this.timerBuffer.GetBytes(), 0, array, 589824, 131072);
			return array;
		}

		/// <inheritdoc />
		// Token: 0x060006B8 RID: 1720 RVA: 0x00022384 File Offset: 0x00020584
		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				SoftBuffer softBuffer = this.inputBuffer;
				if (softBuffer != null)
				{
					softBuffer.Dispose();
				}
				SoftBuffer softBuffer2 = this.outputBuffer;
				if (softBuffer2 != null)
				{
					softBuffer2.Dispose();
				}
				SoftBuffer softBuffer3 = this.memeryBuffer;
				if (softBuffer3 != null)
				{
					softBuffer3.Dispose();
				}
				SoftBuffer softBuffer4 = this.db1BlockBuffer;
				if (softBuffer4 != null)
				{
					softBuffer4.Dispose();
				}
				SoftBuffer softBuffer5 = this.db2BlockBuffer;
				if (softBuffer5 != null)
				{
					softBuffer5.Dispose();
				}
				SoftBuffer softBuffer6 = this.db3BlockBuffer;
				if (softBuffer6 != null)
				{
					softBuffer6.Dispose();
				}
				SoftBuffer softBuffer7 = this.dbOtherBlockBuffer;
				if (softBuffer7 != null)
				{
					softBuffer7.Dispose();
				}
			}
			base.Dispose(disposing);
		}

		/// <inheritdoc />
		// Token: 0x060006B9 RID: 1721 RVA: 0x00022422 File Offset: 0x00020622
		public override string ToString()
		{
			return string.Format("SiemensS7Server[{0}]", base.Port);
		}

		// Token: 0x040001BF RID: 447
		private SoftBuffer inputBuffer;

		// Token: 0x040001C0 RID: 448
		private SoftBuffer outputBuffer;

		// Token: 0x040001C1 RID: 449
		private SoftBuffer memeryBuffer;

		// Token: 0x040001C2 RID: 450
		private SoftBuffer countBuffer;

		// Token: 0x040001C3 RID: 451
		private SoftBuffer timerBuffer;

		// Token: 0x040001C4 RID: 452
		private SoftBuffer db1BlockBuffer;

		// Token: 0x040001C5 RID: 453
		private SoftBuffer db2BlockBuffer;

		// Token: 0x040001C6 RID: 454
		private SoftBuffer db3BlockBuffer;

		// Token: 0x040001C7 RID: 455
		private SoftBuffer dbOtherBlockBuffer;

		// Token: 0x040001C8 RID: 456
		private const int DataPoolLength = 65536;
	}
}
